/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.sgs.mb;

import br.com.sgs.auxiliar.ProcessoAux;
import br.com.sgs.bundle.MessageBundleLoader;
import br.com.sgs.entity.Processo;
import br.com.sgs.fachada.Fachada;
import br.com.sgs.fachada.IFachada;
import java.io.Serializable;
import java.util.Date;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

/**
 *
 * @author Eric
 */
@ManagedBean(name = "processoNewMB")
@ViewScoped
public class ProcessoNewMB implements Serializable {

    @ManagedProperty(value = "#{loginMB}")
    private LoginMB lmb;
    //Campos que receberão as informações de Statuss
    private String orientacao;

    /**
     * Creates a new instance of CampusNewMB
     */
    public ProcessoNewMB() {
    }

    @PostConstruct
    public void init() {
    }

    public String salvar() {
        try {

            Processo processo = new Processo();

            processo.setOrientacao(getOrientacao());
            processo.setDtcriacao(new Date());

            IFachada ifach = new Fachada();
            ifach.inserir(processo);

            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, MessageBundleLoader.getMessage("msgSalvoSucesso"), ""));

            return "PROCESSOLIST";

        } catch (Exception e) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_FATAL, MessageBundleLoader.getMessage("erroNaoEncontrado"), ""));
            e.printStackTrace();
            return null;
        }
    }

    public void limparCampos() {
        try {

            setOrientacao("");

        } catch (Exception e) {
            System.err.println("Erro no limparCampos");
        }
    }

    public String voltar() {
        try {
            return "PROCESSOLIST";
        } catch (Exception e) {
            System.err.println("Erro no método voltar");
            return null;
        }
    }

    /**
     * @param lmb the lmb to set
     */
    public void setLmb(LoginMB lmb) {
        this.lmb = lmb;
    }

    /**
     * @return the lmb
     */
    public LoginMB getLmb() {
        return lmb;
    }

    /**
     * @return the orientacao
     */
    public String getOrientacao() {
        return orientacao;
    }

    /**
     * @param orientacao the orientacao to set
     */
    public void setOrientacao(String orientacao) {
        this.orientacao = orientacao;
    }
}
